package serveur;

import org.jbox2d.collision.shapes.CircleShape;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.dynamics.BodyType;
import org.jbox2d.dynamics.FixtureDef;

import Communication.Mouvement;

public class Fantome extends Objet2D {
	/**
	 * taille d'un Fantome
	 */
	public static final float FANTOME_RAYON = 0.8f;
	private static final float FANTOME_DENSITY = 0.6f;
	private static final float FANTOME_FRICTION = 0.3f;
	private static final float FANTOME_RESTITUTION = 0.5f;

	public int mouvementHorizontal = Mouvement.IMOBILE;
	public int mouvementVertical = Mouvement.IMOBILE;
	
	public Fantome(float posY, float posX) {

		CircleShape cs = new CircleShape();
		cs.m_radius = FANTOME_RAYON;
		setHauteur(2*FANTOME_RAYON);
		setLargeur(2*FANTOME_RAYON);
		
		fixtureDef = new FixtureDef();
		fixtureDef.shape = cs;
		fixtureDef.density = FANTOME_DENSITY;
		fixtureDef.friction = FANTOME_FRICTION;
		fixtureDef.restitution = FANTOME_RESTITUTION;
		
		bodyDef = new BodyDef();
		bodyDef.type = BodyType.DYNAMIC;
		bodyDef.position.set(posX, posY);

	}
	
	public void maj(){
		switch (mouvementVertical) {
		case Mouvement.HAUT:
			body.applyForceToCenter(new Vec2(0f,20f));
			break;
		case Mouvement.BAS:
			body.applyForceToCenter(new Vec2(0f,-20f));
			break;
		default:
			break;
		}
		switch (mouvementHorizontal) {
		case Mouvement.GAUCHE:
			body.applyForceToCenter(new Vec2(-20f,0f));
			break;
		case Mouvement.DROIT:
			body.applyForceToCenter(new Vec2(20f,0f));
			break;
		default:
			break;
		}
	}
	
	public void setMouvementVertical(int mouvement){
		assert(Mouvement.vertical(mouvement));
		System.out.println("mouvementVertical:"+mouvement);
		mouvementVertical = mouvement;
	}

	public void setMouvementHorizontal(int mouvement){
		assert(Mouvement.horizontal(mouvement));
		System.out.println("mouvementHorizontal:"+mouvement);
		mouvementHorizontal = mouvement;
	}
	
	public boolean getImmobile(){
		return false;
	}
	
}
